package com.shangcheng.controller;

import com.shangcheng.common.Result;
import com.shangcheng.entity.TCategory;
import com.shangcheng.entity.TProduct;
import com.shangcheng.service.CatgoryServiceImpl;
import com.shangcheng.service.ProductServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/public")
@CrossOrigin("*")
public class ProductController {
    @Autowired
    CatgoryServiceImpl catService;
    @Autowired
    private ProductServiceImpl service;
    @PostMapping("/products")//新增商品
    public Result<TProduct> addProduct(@RequestBody TProduct product) {//应该是后台管理用户登陆才能操作
        service.addProduct(product);
        return Result.ok(null);
    }
    @GetMapping("/catgorys")
    public Result<List<TCategory>> findCatgorys() {
        return Result.ok(catService.selectAll()) ;
    }
    @GetMapping("/products")
    public Result<List<TProduct>> findProducts() {
        return Result.ok(service.allProducts());
    }


}
